import {DECREMENT, INCREMENT, CHANGEVALUE, ADDITEM, GETNAME, GETSAGA} from "./actionTypes"

const initialState = {
  num: 0,
  list: [1, 23, 4],
  name: '先输入qq'
};
const reducer = (state = initialState, action) => {
  switch (action.type) {
    case DECREMENT:
      const newState = {...state}
      console.log("actionactionactionaction", action)
      return {
        ...newState,
        num: newState.num - 1
      };
    case INCREMENT:
      return {
        ...state,
        num: state.num + 1
      };
    case CHANGEVALUE:
      console.log("changeValue处理dispatch  state:", state, "action:", action)
      return {
        ...state,
        value: action.value
      }
    case ADDITEM:
      console.log("addItem处理dispatch  state:", state, "action:", action)
      const newList = JSON.parse(JSON.stringify(state.list))
      newList.push(state.value)
      return {
        ...state,
        list: newList,
        value: ''
      }
    case GETNAME:
      console.log("getList处理dispatch  state:", state, "action:", action)
      return {
        ...state,
        name: action.name,
        value: ""
      }

    default:
      return state;
  }
};
export default reducer